package com.ita.core;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;

import com.ita.dispatcher.CommandDispatcher;
import com.ita.icommand.impl.AddCmdImpl;
import com.ita.icommand.impl.DelCmdImpl;
import com.ita.icommand.impl.ListCmdImpl;
import com.ita.icommand.impl.SortCmdImpl;
import com.ita.icommand.impl.UpdCmdImlp;
import com.ita.receiver.CommandReceiver;
import com.ita.util.PrintHelper;

/***
 * 主入口
 * 
 * @author ZENGBRl
 *
 */
public class Client {

	public static void start(InputStream in, OutputStream out) {

		PrintHelper.printHelpDoc();
		Scanner scaner = new Scanner(in);
		String input = scaner.nextLine();
		CommandReceiver cReceiver = new CommandReceiver();
		AddCmdImpl acImpl = new AddCmdImpl(cReceiver);
		DelCmdImpl dcImpl = new DelCmdImpl(cReceiver);
		UpdCmdImlp ucImpl = new UpdCmdImlp(cReceiver);
		SortCmdImpl scImpl = new SortCmdImpl(cReceiver);
		ListCmdImpl lcImpl = new ListCmdImpl(cReceiver);
		CommandDispatcher cDispatcher = new CommandDispatcher(acImpl, dcImpl, ucImpl, scImpl, lcImpl);
		do {
			if(input.toUpperCase().equals("Q")){
				PrintHelper.printQuit();
				break;
			}
			cDispatcher.action(input);
			System.out.println("plz enter command");
			input = scaner.nextLine();
		} while (!input.toUpperCase().substring(0, 1).equals("Q"));
		scaner.close();
	}

	public static void main(String[] args) {
		start(System.in, null);
	}
}
